//
//  ViewControllerExtension.swift
//  DemoProject
//
//  Created by Hao on 2018/8/24.
//  Copyright © 2018年 hao. All rights reserved.
//

/// 对 UIViewController 扩展
extension ExtensionStruct where T : UIViewController {
    
    func popOrDismissController(animated: Bool) {
        // 没有导航控制器
        if self.type.navigationController == nil && self.type.presentingViewController != nil {
            self.type.dismiss(animated: animated, completion: nil)
        } else {
            if self.type.presentingViewController != nil && self.type.navigationController?.childViewControllers.count == 1 {
                self.type.dismiss(animated: animated, completion: nil)
            } else {
                self.type.navigationController?.popViewController(animated: animated)
            }
        }
    }
    
}

